﻿package fj.net
{
	import flash.events.EventDispatcher;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLVariables;
	import flash.net.URLRequestMethod;
	
	public class FJRequest extends EventDispatcher
	{
		public var method:String = URLRequestMethod.POST;
		
		private var urlLoader:URLLoader;
		private var urlRequest:URLRequest;
		private var urlVariables:URLVariables;
		
		public function send(url:String, vars:Object):void
		{
			urlLoader = new URLLoader();
			urlRequest = new URLRequest(url);
			urlVariables = new URLVariables();
			
			urlRequest.method = method;
			for (var i in vars){
				urlVariables[i] = vars[i]
			}
			urlRequest.data = urlVariables;
			urlLoader.load(urlRequest);
			urlLoader.addEventListener(Event.COMPLETE,sendComplete);
		}
		private function sendComplete(e:Event)
		{
			var evento:Event = new Event(Event.COMPLETE);
			dispatchEvent(evento);
		}
	}
}